#pragma once

const float TrunkSegHeight = 120.0f;
const float TrunkBaseR = 40.0f;
const int SegNum = 10;
const int SegSlice = 6;
const int SubTrunkSegNum = 4;
const int SubTrunkStart = 4;
const int SubTrunkEnd = 8;
const int SubTrunkNum = SubTrunkEnd - SubTrunkStart;
const int SubTrunkSegSlice = 6;
const float SubTrunkSegHeight = 100.0f;
const int LeafPerTrunk = 20;
const int LeafVNumPerTrunk = LeafPerTrunk * SubTrunkNum * 12;
struct TREETRUNKVERTEX{
	D3DXVECTOR3 p;
	D3DXVECTOR3 normal;
	D3DXVECTOR2 uv;
	static DWORD FVF;
};
class CMUTTree{
public:
	D3DXVECTOR3 SegO[ SegNum+1 ];
	D3DXVECTOR3 SegN[ SegNum ];
	D3DXVECTOR3 SegT[ SegNum ];
	D3DXVECTOR3 SegB[ SegNum ];
	D3DXVECTOR3 SubO[ SubTrunkNum ][ SubTrunkSegNum+1 ];
	D3DXVECTOR3 SubN[ SubTrunkNum ][ SubTrunkSegNum ];
	D3DXVECTOR3 SubT[ SubTrunkNum ][ SubTrunkSegNum ];
	D3DXVECTOR3 SubB[ SubTrunkNum ][ SubTrunkSegNum ];
	CMUTTree() {}
	void InitAll( TREETRUNKVERTEX* verts, WORD* tris, int& vindex, int& tindex, TREETRUNKVERTEX* lverts, WORD* ltris, int& lvindex, int& ltindex );
	void RandTree( D3DXVECTOR3 pos );
	void RandTreeLeaf( TREETRUNKVERTEX* verts, WORD* tris, int& vindex, int& tindex );
	void InitData( TREETRUNKVERTEX* verts, WORD* tris, D3DXVECTOR3* curO, D3DXVECTOR3* curT, D3DXVECTOR3* curN, D3DXVECTOR3* curB, int segNum, int slice, float baseR, float segHeight,int& vindex, int& tindex  );
};

class CMUTTreeSet{
public:
	CMUTTree* trees;
	LPDIRECT3DVERTEXBUFFER9 vb;
	LPDIRECT3DINDEXBUFFER9 ib;
	LPDIRECT3DVERTEXBUFFER9 lvb;
	LPDIRECT3DINDEXBUFFER9 lib;
	LPVOID vertsVoid;
	LPVOID trisVoid;
	LPVOID lvertsVoid;
	LPVOID ltrisVoid;
	int tnum;
	int vnum;
	int fnum;
	int lvnum;
	int lfnum;
	CMUTTreeSet() : vertsVoid(0), trisVoid(0), lvertsVoid(0), ltrisVoid(0), trees(0), tnum(0), vb(0), ib(0), vnum(0), fnum(0), lvb(0), lib(0)  {}
	HRESULT Create( HANDLE hEvent, int num );
	void RenderTrunk();
	void RenderLeaf();
	void InitData( D3DXVECTOR3 bias, D3DXVECTOR3* pos );
	void Release( HANDLE hEvent );
};